package routers

import (
	"alertmanagerWebhook/api"
	"alertmanagerWebhook/config"
	"net/http"
	"alertmanagerWebhook/global"
	"github.com/gin-gonic/gin"
)

func (router RouterGroup) SendDingDing_alert_Router() {
	router.POST("v1/dingding", func(c *gin.Context) {
		var notification config.Notification

		// 从请求主体中解析 JSON 数据到 notification
		err := c.ShouldBindJSON(&notification)
		if err != nil {
			global.Logger.Errorf("Error shouldbingjson dingding:%v\n",err.Error())
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
			return
		}

		// 调用 api.SendToDingding 并传递 notification
		api.SendToDingding(c, notification)

		// 如果需要，可以返回成功响应
		c.JSON(http.StatusOK, gin.H{"status": "success"})
	})
}
